using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyFSMSystem
{
    private List<IEnemyFSM> mStates = new List<IEnemyFSM>();
    private IEnemyFSM mCurrentState;
    public IEnemyFSM CurrentState { get => mCurrentState; set => mCurrentState = value; }
    public void AddState(IEnemyFSM state)
    {
        if (state == null)
        {
            Debug.LogWarning("5555");
        }
        if (mStates.Count == 0)
        {
            mStates.Add(state);
            mCurrentState = state;
            return;
        }
        foreach (IEnemyFSM item in mStates)
        {
            if (item.StateId == state.StateId)
            {
                Debug.LogWarning("5555");
                return;
            }
        }
        mStates.Add(state);
    }
    public void DeletStatee(e_EnemystateId id)
    {
        if (id == e_EnemystateId.NullStat)
        {
            Debug.LogWarning("55555");
            return;
        }
        foreach (IEnemyFSM item in mStates)
        {
            if (item.StateId == id)
            {
                mStates.Remove(item);
                return;
            }
        }
        Debug.LogWarning("5555");
    }
    public void PerformTransition(e_Enemystate state)
    {
        if (state == e_Enemystate.NullTransition)
        {
            Debug.LogWarning("555555");
            return;
        }
        e_EnemystateId nextid = CurrentState.GetStateId(state);
        if (nextid == e_EnemystateId.NullStat)
        {
            Debug.LogWarning("555555");
        }
        if (nextid == CurrentState.StateId)
        {
            return;
        }
        foreach (IEnemyFSM item in mStates)
        {
            if (item.StateId == nextid)
            {
                mCurrentState.DoBeforeLave();
                mCurrentState = item;
                mCurrentState.DoBeforeEnter();
                return;
            }
        }
        Debug.Log("555555");
    }
}
